package article10.equals;

import java.awt.*;
import java.util.Objects;

/**
 * Adds a value component without violating the equals contract
 * 添加一个值组件而不违反Equals协定
 *
 * @Author: cctv
 * @Date: 2019/4/2 16:16
 */
public class ColorPoint1 {
    private final Point point;
    private final Color color;

    public ColorPoint1(int x, int y, Color color) {
        point = new Point(x, y);
        this.color = Objects.requireNonNull(color);
    }

    /**
     * Returns the point-view of this color point
     * @return
     */
    public Point asPoint() {
        return point;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof ColorPoint1))
            return false;
        ColorPoint1 cp = (ColorPoint1) o;
        return cp.point.equals(point) && cp.color.equals(color);
    }

}
